﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using DeepEarth.Toolkit.Geometry.Data;
using DeepEarth.Toolkit.Geometry;

namespace ExampleApplication.Examples
{
    public partial class AddBitmapLayer : Page
    {
        public AddBitmapLayer()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DrawShapes();
        }

        void DrawShapes()
        {
            int shapeCount = 500;
            BitmapLayer bml = new BitmapLayer();

            Random rng = new Random(0);
            var lines = GenerateLines(shapeCount, rng);
            var polys = GeneratePolygons(shapeCount, rng);

            for (int i = 0; i < shapeCount; i++)
            {
                var l = lines[i];
                bml.Add(l);

                var p = polys[i];
                bml.Add(p);
            }

            this.map.BaseChildren.Add(bml);
        }

        List<LineStringGeometry> GenerateLines(int linecount, Random rng)
        {
            List<LineStringGeometry> lines = new List<LineStringGeometry>();

            for (int i = 0; i < linecount; i++)
            {
                int points = rng.Next(2, 5);
                var lsg = Utilities.Utilities.RandomLineStringGeometry(rng, points);
                lsg.Stroke = Utilities.Utilities.RandomStroke(rng);
                lsg.StrokeThickness = rng.Next(1, 3);
                lines.Add(lsg);
            }

            return lines;
        }

        List<PolygonGeometry> GeneratePolygons(int polycount, Random rng)
        {
            List<PolygonGeometry> polys = new List<PolygonGeometry>();

            for (int i = 0; i < polycount; i++)
            {
                int points = rng.Next(4, 6);
                var p = Utilities.Utilities.RandomPolygonGeometry(rng, points);
                p.Fill = Utilities.Utilities.RandomStroke(rng);
                polys.Add(p);
            }

            return polys;
        }
    }
}
